<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>背景图片固定</title>
</head>
<body>
    <div class="content">
        <h3>测试文字</h3>
        <p>视觉差效果</p>
    </div>
    <div class="parallax p1"><h3>第1个图片</h3></div>
    <div class="content">.........</div>
    <div class="parallax p2"><h3>第2个图片</h3></div>
    <div class="content">.........</div>
    <div class="parallax p3"><h3>第3个图片</h3></div>
    <div class="content">.........</div>
    <style>
        .parallax{
            width: 100%;
            height: 80vh;
            position: relative;
            overflow: hidden;
            background-repeat: no-repeat;
            background-size: cover;
            background-position: top center;
            /* 关键属性 */
            background-attachment: fixed;
        }
        .p1{
           background-image: url('https://picsum.photos/1920/1080?1');
        }
        .p2{
           background-image: url('https://picsum.photos/1920/1080?2');
        }
        .p3{
           background-image: url('https://picsum.photos/1920/1080?3');
        }
        .content{
            width: 960px;
            height: 40vh;
            margin: 0 auto;
            text-align: justify;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
        }
        h3{
            font-size: 45px;
            letter-spacing: 10px;
            text-align: center;
            color: #000;
            font-weight: 400;
        }
        p{
            color: #000;
            font-size: 16px;
            line-height: 28px;
        }
    </style>
</body>
</html>